--怀璧其罪
local huaibiqizui = fk.CreateSkill {
    name = "mcdh_huaibiqizui",
    tags = {Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

huaibiqizui:addEffect(fk.CardShown,{
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) and player == target  then
            for _, id in ipairs(data.cardIds) do
                if player:getMark("huaibiqizui_"..Fk:getCardById(id):getTypeString().."-turn") < 2 then
                    return true
                end
            end
        end
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = room.current
        room:setPlayerMark(to, "@@huaibiqizui", 1)
    end,
})

huaibiqizui:addEffect(fk.CardShown,{
    can_refresh = function(self, event, target, player, data)
        return player:hasSkill(self) and player == target
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        local  mark = {}
        for _, id in ipairs(data.cardIds) do
                if  not table.contains(mark,Fk:getCardById(id):getTypeString())then
                    table.insertIfNeed(mark,Fk:getCardById(id):getTypeString())
                end
        end
        for _, type in ipairs(mark) do
            room:addPlayerMark(player,"huaibiqizui_"..type.."-turn",1)
        end
    end
})

huaibiqizui:addEffect(fk.PreCardUse,{
    can_refresh = function(self, event, target, player, data)
        return target == player and player:getMark("@@huaibiqizui") ~= 0
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "@@huaibiqizui", 0)
    end
})

huaibiqizui:addEffect('targetmod',{
    bypass_times = function(self, player, skill, scope, card, to)
        return player:getMark("@@huaibiqizui") ~= 0
    end,
    bypass_distances = function(self, player, skill, card, to)
        return  player:getMark("@@huaibiqizui") ~= 0
    end,
})

Fk:loadTranslationTable{
    ["mcdh_huaibiqizui"] = "怀璧其罪",
    [":mcdh_huaibiqizui"] = "锁定技，当你展示牌后，若其中包含本回合你未展示过的类型，当前回合角色使用的下一张牌无次数、距离限制。",
    ["@@huaibiqizui"] = "怀璧其罪",
}
return huaibiqizui